package com.dce.dev.api.common.tools.json;

import java.io.IOException;
import java.util.Date;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

/**
 * 日期类型序列化器
 * <p>
 * 将 {@link Date} 类型值转换为 long 类型值
 */
public class DateJsonSerializer extends JsonSerializer<Date> {
    @Override
    public void serialize(final Date value, final JsonGenerator jgen, final SerializerProvider provider)
            throws IOException {
        if (value != null) {
            final long milliseconds = value.getTime();
            jgen.writeNumber(milliseconds);
        }
    }
}
